package com.gotobject.junit.internal;

import com.google.inject.TypeLiteral;
import com.google.inject.Provider;

import java.util.List;
import java.util.ArrayList;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author Huascar A. Sanchez (huascar.sanchez@gmail.com)
 */
public class GuiceUtil {
    private GuiceUtil(){}

    @SuppressWarnings("unchecked")
    public static <T> TypeLiteral<List<T>> listOf(final Class<T> parameterType) {
        return (TypeLiteral<List<T>>) TypeLiteral.get(
                new ParameterizedType() {
                    public Type[] getActualTypeArguments(){
                        return new Type[]{parameterType};
                    }
                    public Type getRawType() {
                        return List.class;
                    }
                    public Type getOwnerType() {
                        return null;
                    }
                });
    }
    @SuppressWarnings("unchecked")
    public static <T> TypeLiteral<ArrayList<T>> arrayListOf(final Class<T> parameterType) {
        return (TypeLiteral<ArrayList<T>>) TypeLiteral.get(
                new ParameterizedType() {
                    public Type[] getActualTypeArguments(){
                        return new Type[]{parameterType};
                    }
                    public Type getRawType() {
                        return ArrayList.class;
                    }
                    public Type getOwnerType() {
                        return null;
                    }
                }
        );
    }
}
